highcharts / highcharts-android

Android wrapper for Highcharts usage
Other
126 stars 30 forks source link

Unable to change the colors for stacked column for Bar graph #291

Open Venkataramana0801 opened 2 weeks ago

Venkataramana0801 commented 2 weeks ago

In my application, I want to display the group data in the bar graph. So I am using the stacked column provided by High chart demo sample. I am able to display the graph successfully by using the below code

  HIOptions options = new HIOptions();

        HITitle title = new HITitle();
        title.setText("Stacked column chart");
        options.setTitle(title);

        HISubtitle subtitle = new HISubtitle();
        subtitle.setText("Plain");
        options.setSubtitle(subtitle);

        HIXAxis xaxis = new HIXAxis();
        xaxis.setCategories(new ArrayList<>(Arrays.asList("Appled", "Oranges", "Pears", "Grapes", "Bananas")));
        options.setXAxis(new ArrayList<>(Collections.singletonList(xaxis)));

        HIYAxis yaxis = new HIYAxis();
        yaxis.setMin(0);
        yaxis.setTitle(new HITitle());
        yaxis.getTitle().setText("Total fruit consumption");
        yaxis.setStackLabels(new HIStackLabels());
        yaxis.getStackLabels().setEnabled(true);
        yaxis.getStackLabels().setStyle(new HICSSObject());
        yaxis.getStackLabels().getStyle().setFontWeight("bold");
        yaxis.getStackLabels().getStyle().setColor("gray");
        options.setYAxis(new ArrayList<>(Collections.singletonList(yaxis)));

        HILegend legend = new HILegend();
        legend.setAlign("right");
        legend.setX(-30);
        legend.setVerticalAlign("top");
        legend.setY(25);
        legend.setFloating(true);
        legend.setBackgroundColor(HIColor.initWithName("white"));
        legend.setBorderColor(HIColor.initWithHexValue("ccc"));
        legend.setBorderWidth(1);
//        legend.setShadow(false);
        options.setLegend(legend);

        HITooltip tooltip = new HITooltip();
        tooltip.setPointFormat("{series.name}: {point.y}<br/>Total: {point.stackTotal}");
        tooltip.setHeaderFormat("<b>{point.x}</b><br/>");
        options.setTooltip(tooltip);

        HIPlotOptions plotoptions = new HIPlotOptions();
        plotoptions.setColumn(new HIColumn());
        plotoptions.getColumn().setStacking("normal");

        options.setPlotOptions(plotoptions);

        HIColumn column1 = new HIColumn();
        column1.setName("John");
        Number[] column1Data = new Number[]{5, 3, 4, 7, 2};
        String[] column1DataColor1 = new String[]{"#8B008B", "#8B008B", "#8B008B", "#8B008B", "#8B008B"};
        column1.setData(new ArrayList<>(Arrays.asList(column1Data)));
        column1.setColors(new ArrayList<>(Arrays.asList(column1DataColor1)));

        HIColumn column2 = new HIColumn();
        column2.setName("Jane");
        Number[] column2Data = new Number[]{2, 2, 3, 2, 1};
        String[] column1DataColor2 = new String[]{"#5F9EA0", "#5F9EA0", "#5F9EA0", "#5F9EA0", "#5F9EA0"};
        column2.setData(new ArrayList<>(Arrays.asList(column2Data)));
        column2.setColors(new ArrayList<>(Arrays.asList(column1DataColor2)));

        options.setSeries(new ArrayList<>(Arrays.asList(column1, column2)));
        chartView.setOptions(options);

Capture_stackedcolumn

Here I want to change the two colors of the graph, for that I am using the below code, but I am unable to change the colors

 String[] column1DataColor1 = new String[]{"#8B008B", "#8B008B", "#8B008B", "#8B008B", "#8B008B"};
column1.setColors(new ArrayList<>(Arrays.asList(column1DataColor1)));
  String[] column1DataColor2 = new String[]{"#5F9EA0", "#5F9EA0", "#5F9EA0", "#5F9EA0", "#5F9EA0"};
  column2.setColors(new ArrayList<>(Arrays.asList(column1DataColor2)));

Here I am able to change the one color for the graph by using the below code options.setColors(new ArrayList<>(Arrays.asList(column1DataColor1)));

Here I want to change the two colors. how to change the graph for two colors.

Thanks In Advance.