go-chart icon indicating copy to clipboard operation
go-chart copied to clipboard

Chart render on Windows is weird.

Open AllenDang opened this issue 6 years ago • 0 comments

I found the chart render on Windows 7 is incomplete and weird. Below is the chart rendered by same code on MacOS and Windows.

The X Axis is missing and transparent background doesn't work on Windows.

I'm using the latest checkout from main branch.

MacOS 截屏2019-12-10下午5 53 42

Windows WechatIMG2672

Here is the code I'm using to generate the chart.

  graph := chart.Chart{
		Width:  width,
		Height: height,
		Font:   f,
		Background: chart.Style{
			Padding: chart.Box{
				Top:  20,
				Left: 20,
			},
			FillColor: drawing.Color{R: 1, G: 1, B: 1, A: 0},
		},
		Canvas: chart.Style{
			FillColor: drawing.Color{R: 1, G: 1, B: 1, A: 0},
		},
		XAxis: chart.XAxis{
			Style: chart.Style{
				StrokeColor: drawing.ColorWhite,
				FontColor:   drawing.ColorWhite,
			},
			ValueFormatter: chart.TimeDateValueFormatter,
		},
		YAxis: chart.YAxis{
			Style: chart.Style{
				StrokeColor: drawing.ColorWhite,
				FontColor:   drawing.ColorWhite,
			},
		},
		Series: []chart.Series{
			chart.TimeSeries{
				Name: "充值金额",
				Style: chart.Style{
					StrokeWidth: 2,
				},
				XValues: weekSeries,
				YValues: paidSeries,
			},
			chart.TimeSeries{
				Name: "消息条数",
				Style: chart.Style{
					StrokeWidth: 2,
				},
				XValues: weekSeries,
				YValues: msgSeries,
			},
		},
	}

	graph.Elements = []chart.Renderable{
		chart.Legend(&graph, chart.Style{
			StrokeColor: drawing.ColorWhite,
			FontColor:   drawing.ColorWhite,
			FillColor:   drawing.Color{R: 1, G: 1, B: 1, A: 0},
		}),
	}

	collector := &chart.ImageWriter{}
	graph.Render(chart.PNG, collector)

	img, _ := collector.Image()
	if r, ok := img.(*image.RGBA); ok {
		return r
	}

	return nil

AllenDang avatar Dec 10 '19 09:12 AllenDang